function reactive(target = {}) {
  // 不是对象或数组
  if (typeof target !== 'object' || target === null) return target
  // 代理配置项
  const observed = new Proxy(target, {
    get(target, key, receiver) {
      const result = Reflect.get(target, key, receiver)
      return reactive(result) // 深度监听
    },
    set(target, key, val, receiver) {
      if (val === target[key]) return true // 判重
      return Reflect.set(target, key, val, receiver)
    },
    deleteProperty(target, key) {
      return Reflect.deleteProperty(target, key)
    }
  })
  return observed
}

const data = {
  realName: 'zhangsan'
}
const user = reactive(data)
user.realName = 'lisi'
console.log(user.realName) // lisi
